const fs = require('fs');

let html = fs.readFileSync('./basic.html').toString();
const list = html.match(/<a\shref="[\w\/]+"\sclass="[\w-]+">[\w\s\u4e00-\u9fa5]+[<\/a>]{4,4}/g) || [];
console.log(list);
const catalog = [];

list.forEach((item, index) => {
  const [url, title] = item
    .replace(/<a\shref="([\w\/]+)"\sclass="[\w-]+">([\w\s\u4e00-\u9fa5]+)[<\/a>]{4,4}/, '$1;$2')
    .split(';');

  catalog.push({
    index,
    level: '##',
    url,
    title,
  });
});

fs.writeFile('./catalog.json', JSON.stringify(catalog), {}, (error) => {
  if (error) {
    return console.error(error);
  }
});

console.log(catalog);
